package com.itheima.mapper;

import com.itheima.pojo.Sif;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface SifMapper {

    // 插入数据
    @Insert("insert into sif (timestamp, sif) " +
            "values (#{timestamp}, #{sif})")
    void add(Sif sif);

    // 查询数据，根据TimeStamp
    @Select("select * from sif where timestamp = #{timestamp}")
    Sif findSifByTimestamp(LocalDateTime timestamp);

    // 查询数据，返回在TimeStamp在startTime到EndTime之间的所有数据
    @Select("select * from sif where timestamp between #{startTime} and #{endTime}")
    List<Sif> findSifByTimeRange(LocalDateTime startTime, LocalDateTime endTime);

    // 更新数据
    @Update("update sif set sif = #{sif} where timestamp = #{timestamp}")
    void update(Sif sif);

    // 查询数据库中现有数据的最新日期的当天的全部数据
    @Select("select * from sif where date(timestamp) = (select max(date(timestamp)) from sif)")
    List<Sif> findSifInLatestDayData();

    // 查询表中的数据总条数
    @Select("select count(*) from sif")
    Integer findSifAllNumber();
}
